<?php
	global $SSO, $Security, $AppID, $User, $DB;
	//Check to see if there is a valid session 
	$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
	
	//Check to see if the user has rights to be on LWAdmin
	$PageRights = array('ADMIN', 'USERADMIN');
	$Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);

	global $SSO;
	$validator = new FormValidation();
	if(isset($_POST['txtUsername']))
	{
		if(!$SSO->CheckUserExists($_POST['txtUsername']))
		{
			$validator->validateForm('fdf/Admin_Users_frmNewUser.xml');
			header("Location: index.php?action=users_new&step=2&username=" . $_POST['txtUsername']);
			exit();
		}
		if($SSO->CheckUserExists($_POST['txtUsername']))
		{
			$_POST['val_txtUsername'] = $_POST['txtUsername'];
			$_POST['err_txtUsername'] = 'Username already exists.';
			$_ENV['array_of_like_users'] = $SSO->GetTakenLikeUsers($_POST['txtUsername']);
		}
	}
?>
<form action="index.php?action=users_new&amp;step=1" method="post" name="frmNewUser">
<table cellpadding="0" cellspacing="0" border="0" style="border-spacing:0px;border:0px;" width="80%" align="center">
	<tr>
		<td>&nbsp;
		</td>
	</tr>				
	<tr>
		<td><span class="T1">Please enter the username you desire for your new user.  Usernames must be any combination of 5 to 15 lower/upper-case letters or numbers.</span>
		</td>
	</tr>				
	<tr>
		<td>&nbsp;
		</td>
	</tr>				
	<tr>
		<td align="center">
			<table cellpadding="0" cellspacing="0" border="0">
				<?php
				if(isset($_ENV['array_of_like_users']))
				{
					print "<tr><td align='center'><span class='T1Small'><b>Similar Taken Users</b><br>";
					$array_index = 0;
					while($array_index < sizeof($_ENV['array_of_like_users']))
					{
						print $_ENV['array_of_like_users'][$array_index] . "<br>";
						$array_index++;
					}
					print "<br></span></td></tr>";
				}
				?>
				<tr>
					<td>
						<span class="T1">Desired Username</span>&nbsp;&nbsp;&nbsp;
					</td>
				</tr>
				<tr>
					<td>
						<input name="txtUsername" class="T1" type="text" value="<?php print $validator->getPostIfSet("val_txtUsername"); ?>">
					</td>
				</tr>
				<tr>
					<td>
						<span class="T0" style="color:#FF0000"><?php print $validator->getPostIfSet("err_txtUsername"); ?></span>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td><br>
		</td>
	</tr>
	<tr>
		<td align="center">
			<input type="submit" name="btnCreateUser" class="B" value="Create Username">&nbsp;&nbsp;&nbsp;
			<input type="button" name="btnCancel" class="B" value="Cancel" onClick="location.href='index.php?action=users';">
		</td>
	</tr>
	<tr>
		<td height="1"><img src="images/1pixel.gif" height="8" border="0" alt="">
		</td>
	</tr>
</table> 

</form>
